﻿Imports System.Windows.Forms
Imports LRS.BLL
Public Class MainForm

    'Check if this is the first time application is opened
    Private Function CheckTheFirstTime() As Boolean
        If (bEmployee.GetNumberOfEmployee() = 0) Then
            Return True
        Else
            Return False
        End If
    End Function
    Private Sub DoLogin()
        Dim login As LoginForm = New LoginForm()
        While (True)
            Dim result = login.ShowDialog()
            If (result = Windows.Forms.DialogResult.Cancel) Then
                Application.Exit()
                Exit While
            End If
            Dim username As String = login.UsernameTextBox.Text
            Dim password As String = login.PasswordTextBox.Text
            If (bEmployee.ValidateAccount(username, password)) Then
                If (LRSInfo.Type.Equals("Admin")) Then
                    picManageEmployee.Enabled = True
                Else
                    picManageEmployee.Enabled = False
                End If
                Exit While
            Else
                MessageBox.Show("Tên đăng nhập hoặc mật khẩu không hợp lệ")
            End If

        End While
    End Sub
    Private Sub GetAdminInfo()
        Dim adminForm As AdminLogin = New AdminLogin()
        adminForm.ShowDialog()
    End Sub
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LRSInfo.FineFactor = Single.Parse(bConfiguration.GetPropertyValue("FineFactor"))
        LRSInfo.MaxDay = Integer.Parse(bConfiguration.GetPropertyValue("MaxDay"))
        LRSInfo.MaxQuantity = Integer.Parse(bConfiguration.GetPropertyValue("MaxQuantity"))
        If (CheckTheFirstTime()) Then
            GetAdminInfo()
        End If
        DoLogin()

    End Sub

    Private Sub picButton_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picReceive.MouseLeave, picNewOrder.MouseLeave, picManageSupplier.MouseLeave, picManageProduct.MouseLeave, picManageManufacturer.MouseLeave, picManageEmployee.MouseLeave, picManageCustomer.MouseLeave, picConfiguration.MouseLeave, picExit.MouseLeave
        Cursor = Cursors.Default
    End Sub

    Private Sub picButton_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picReceive.MouseEnter, picNewOrder.MouseEnter, picManageSupplier.MouseEnter, picManageProduct.MouseEnter, picManageManufacturer.MouseEnter, picManageEmployee.MouseEnter, picManageCustomer.MouseEnter, picConfiguration.MouseEnter, picExit.MouseEnter
        Cursor = Cursors.Hand
    End Sub

    Private Sub picNewOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picNewOrder.Click
        Dim orderForm As CreateOrder = New CreateOrder()
        Me.Hide()
        orderForm.ShowDialog()
        Me.Show()
    End Sub

    Private Sub picExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picExit.Click
        Me.Hide()
        DoLogin()
        Me.Show()
    End Sub

    Private Sub picManageOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picReceive.Click
        Dim manageOrder As ManageOrder = New ManageOrder()
        Me.Hide()
        manageOrder.ShowDialog()
        Me.Show()
    End Sub

    Private Sub picManageCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picManageCustomer.Click
        Dim manageCustomer As ManageCustomer = New ManageCustomer()
        Me.Hide()
        manageCustomer.ShowDialog()
        Me.Show()
    End Sub

    Private Sub picManageSupplier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picManageSupplier.Click
        Dim manageSupplier As ManageSupplier = New ManageSupplier()
        Me.Hide()
        manageSupplier.ShowDialog()
        Me.Show()
    End Sub

    Private Sub picManageManufacturer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picManageManufacturer.Click
        Dim manageManufacturer As ManageManufacturer = New ManageManufacturer()
        Me.Hide()
        manageManufacturer.ShowDialog()
        Me.Show()
    End Sub

    Private Sub picManageEmployee_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picManageEmployee.Click
        Dim manageEmployee As ManageEmployee = New ManageEmployee()
        Me.Hide()
        manageEmployee.ShowDialog()
        Me.Show()
    End Sub

    Private Sub picManageProduct_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picManageProduct.Click
        Dim manageProduct As ManageProduct = New ManageProduct()
        Me.Hide()
        manageProduct.ShowDialog()
        Me.Show()
    End Sub

    Private Sub picConfiguration_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picConfiguration.Click
        Dim config As ConfigurationForm = New ConfigurationForm()
        Me.Hide()
        config.ShowDialog()
        Me.Show()
    End Sub
End Class